<?php 
require_once "Model.php";
require_once "../Common/connDB.php";
	class goodsModel extends Model{
		public function __construct(){
			parent::__construct();
		}
		public function getgoodslist(){
		
			$sql="select * from goods";
			$data=$this->conn->query($sql);
			return $data;
		}
		
		public function addgoodsInfo(){

			
			$pic=$this->uploadfile("pic",'../images/');
			$goodsname=$_POST["goodsname"];
			$tid=$_POST['goodstype'];
			$brand=$_POST["brand"];
            $place=$_POST["place"];
			$intro=$_POST["intro"];			
            
		    $sql="insert into goods values (null,'$goodsname','$tid','$brand','$intro','$place',now(),'$pic')";
		    echo $sql;
		    $result=$this->conn->query($sql);
		    return $result;
		}
	
		public function getgoodsbyID(){
			$gid=$_GET['gid'];
			$sql="select * from goods where gid=$gid";
			$data=$this->conn->query($sql);
			return $data;
		}
		public function updategoodsInfo(){
		
			$pic=$this->uploadfile("pic",'images/');
			$gid=$_POST["gid"];
			$goodsname=$_POST["goodsname"];
			$tid=$_POST['tid'];
			$brand=$_POST["brand"];
            $place=$_POST["place"];
			$intro=$_POST["intro"];
            $adddate=$_POST["adddate"];			
            
			if($pic==null){
				$sql="update goods set goodsname='{$goodsname}',tid='{$tid}',brand='{$brand}',place='{$place}',intro='$intro',adddate='$adddate' where gid=$gid";
			}else{
				$sql="update goods set goodsname='{$goodsname}',brand='{$brand}',place='{$place}',intro='$intro',adddate='$adddate',pic='$pic' where gid=$gid";
			}
			 		
			$result=$this->conn->query($sql);//写入数据库
			return $result;
			
		}
		public function del(){
			$gid=$_GET['gid'];
			$sql="delete from goods where gid={$gid}";			
			$result=$this->conn->query($sql);
			return $result;
		}
	}

 ?>